package HomeService

import (
	"context"
	"fmt"
	"gdshop-font-api-go/app/request/HomeReq"
	"gdshop-font-api-go/app/response/HomeResp"
	"gdshop-font-api-go/library/response"
	"strings"
)

func Pcas(ctx context.Context, parames *HomeReq.Pcas) *response.JsonResponse {
	fmt.Println(parames.Code[0:2])
	rPcas := HomeResp.Pcas{}
	if find := strings.Contains(parames.Type, "p"); find {
		rPcas.Provinces = getAreaLevel(ctx, 1)
	}
	if find := strings.Contains(parames.Type, "c"); find {
		rPcas.Citys = getAreaPCode(ctx, parames.Code[0:2])
	}
	if find := strings.Contains(parames.Type, "a"); find {
		rPcas.Areas = getAreaPCode(ctx, parames.Code[0:4])
	}
	if find := strings.Contains(parames.Type, "s"); find {
		rPcas.Streets = getAreaPCode(ctx, parames.Code[0:6])
	}
	return response.SuccessByRequestMessageData(nil,
		"成功",
		rPcas,
	)
}
